package Server.ServerCore.Controller;

import Server.ServerCore.Model.Player.PlayerInstance;
import Server.ServerCore.Service.DataPacks.packRequest.Stop_request;
import Server.ServerCore.Service.DataPacks.packRespose.bust_response;
import Server.ServerCore.Service.Logic.HandleController;
import Server.ServerCore.Service.Logic.RegisterPack;
import Server.ServerCore.Service.service.PlayerManagerService;
import org.jboss.netty.buffer.ChannelBuffer;
import org.springframework.stereotype.Service;

/**
 * @author :石头哥哥<br/>
 *         Project:21Server
 *         Date: 13-4-10
 *         Time: 下午10:00
 *         StopCardController=29
 *
 *         ok  21点，玩家黑杰克直接发送该包获取下一个位置的牌
 */
@Service
public class StopCardController extends HandleController {


    private static final long serialVersionUID = 8630336313297928076L;

    /**
     * 数据分解具体处理的函数
     *
     * @param buffer buffer
     * @param player player
     */
    @Override
    public void DispatchPack(ChannelBuffer buffer, PlayerInstance player) throws Exception {
        Stop_request stopRequest= (Stop_request) parseObject(buffer,Stop_request.class);
        //返回nextcircleUnitID
        bust_response bustResponse=new bust_response();
        if (player.getNowCrileUnitID()==stopRequest.getCircleUnitID()&&stopRequest.getCircleUnitID()!=5){
            int nextID=PlayerManagerService.getNextcircleUnitID(player, stopRequest.getCircleUnitID());
            bustResponse.setNextcircleUnitID(nextID);
            if (nextID!=-1){
                player.setNowCrileUnitID(nextID);
            }
            player.DirectSend(bustResponse.getJsonData(2,9));
        }

    }

    /**
     * 通过spring产生处理数据的controller，储存在数组中
     */
    @Override
    public void InitiController() {
        RegisterPack.GAME_CONTROLLERS[29]=this;
    }
}
